﻿using System;
using System.IO;
using System.Xml.Serialization;
using ClassLibrary.Configuration.Switch;
using ClassLibrary.SignalType.SynchronousTransportModuleLevel1.VirtualContainer;

namespace ConfigGenerator
{
    class SwitchConfigGenerator
    {
        public SwitchConfigGenerator(String outputPath)
        {
            var switchingTable = new ConfSwitchingTable()
            {
                Records = new[]
                        {
                            new ConfSwitchingTable.Record()
                                {
                                    Ingress = new ConfSwitchingTable.Record.SwitchingPair() {PortId = 0, VcId = 0},
                                    Egress = new ConfSwitchingTable.Record.SwitchingPair() {PortId = 1, VcId = 1}
                                },
                            new ConfSwitchingTable.Record()
                                {
                                    Ingress = new ConfSwitchingTable.Record.SwitchingPair() {PortId = 0, VcId = 1},
                                    Egress = new ConfSwitchingTable.Record.SwitchingPair() {PortId = 1, VcId = 0}
                                },
                            new ConfSwitchingTable.Record()
                                {
                                    Ingress = new ConfSwitchingTable.Record.SwitchingPair() {PortId = 1, VcId = 0},
                                    Egress = new ConfSwitchingTable.Record.SwitchingPair() {PortId = 0, VcId = 1}
                                },
                            new ConfSwitchingTable.Record()
                                {
                                    Ingress = new ConfSwitchingTable.Record.SwitchingPair() {PortId = 1, VcId = 1},
                                    Egress = new ConfSwitchingTable.Record.SwitchingPair() {PortId = 0, VcId = 0}
                                },

                        }
            };

            var switchConfiguration = new SwitchConfig() 
            { 
                Id = "Switch0",
                ConfSwitchingTable = switchingTable,
                LogicalPortsNo = 2,
                MultiplexerInfos = new[]
                    {
                        new MultiplexerInfo()
                            {
                                EgressLogicalPortId = 0,
                                FirstIngressPhysicalPortId = 0,
                                IngressPortsNo = 2,
                                VcTypes = new VCType[]{VCType.VC12, VCType.VC12 }
                            }
                    }, 
                PhysicalPortsNo = 2, 
                WireCloudIp = "127.0.0.1", 
                WireCloudPort = 9050,
                ManagerIp = "127.0.0.1",
                ManagerPort = 9049,
                ClockDuration = 2000
            };

            var writer = new XmlSerializer(typeof(SwitchConfig));
            using (var file = File.Create(outputPath))
            {
                writer.Serialize(file, switchConfiguration);
            }

        }
    }

}
